package demo;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class SwingButton extends JFrame {

	private JPanel contentPane;
	private JTextField txtusername;
	private JTextField PWDpassword;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					SwingButton frame = new SwingButton();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public SwingButton() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("用户名");
		lblNewLabel.setBounds(46, 31, 54, 15);
		contentPane.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("密码");
		lblNewLabel_1.setBounds(46, 56, 54, 15);
		contentPane.add(lblNewLabel_1);
		
		txtusername = new JTextField();
		txtusername.setBounds(110, 28, 260, 21);
		contentPane.add(txtusername);
		txtusername.setColumns(10);
		
		PWDpassword = new JTextField();
		PWDpassword.setBounds(110, 53, 260, 21);
		contentPane.add(PWDpassword);
		PWDpassword.setColumns(10);
		
		JButton btnNewButton = new JButton("登录");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String username = txtusername.getText();
				String password = PWDpassword.getText();
				if("zs".equalsIgnoreCase(username)&&"123456".equals(password)){
					JOptionPane.showMessageDialog(null, "登录成功");
				}else{
					JOptionPane.showMessageDialog(null, "登录失败");
				}
				
			}
		});
		btnNewButton.setBounds(257, 92, 93, 23);
		contentPane.add(btnNewButton);
		
		JButton cz = new JButton("重置");
		cz.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
//				String reset = cz.getText();
				txtusername.setText("");
				PWDpassword.setText("");
//				if("".equals(txtusername)&&"".equals(PWDpassword))
				JOptionPane.showMessageDialog(null, "重置成功");
			}
		});
		cz.setBounds(154, 92, 93, 23);
		contentPane.add(cz);
	}
}
